<?php
/**
 * 在base64_encode后字符串存在+时，setrawcookie和setcookie的不同点，以及引发$_COOKIE读取结果不对的问题
 * @version $Id: cookie_plus_raw.php 185 2011-05-02 02:43:57Z horseluke@126.com $
 */
ob_start();
$servinfo = array();
$servinfo['os'] = PHP_OS;
$servinfo['web_software'] = isset($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : 'UNKNOWN_SERVER_SOFTWARE';
$servinfo['php_version'] = PHP_VERSION;
$servinfo['php_runmode'] = PHP_SAPI;

echo implode('/', $servinfo);
echo '<br />';

$data_ori = '14356%%@#$ ~!#!`1321`3`&^%+++++++';
$data = base64_encode($data_ori);   //存在+号
echo 'AFTER base64_encode OF "'. $data_ori. '", THE RESULT IS:"'. $data. '"';
echo '<br />';

if(!isset($_COOKIE['a'])){
	setcookie('a', $data, 0);
	echo 'REFRESH THE PAGE TO SEE setcookie to $_COOKIE[\'a\']';
}else{
	echo 'AFTER setcookie:'. $_COOKIE['a'];
}

echo '<br />';

if(!isset($_COOKIE['b'])){
	setrawcookie('b', $data, 0);
	echo 'REFRESH THE PAGE TO SEE setrawcookie to $_COOKIE[\'b\']';
}else{
	echo 'AFTER setrawcookie:'. $_COOKIE['b'];
}
//cookies存在+号导致当setrawcookie后再读取时，与实际不符

echo '<br />';

if(!isset($_COOKIE['c'])){
	setrawcookie('c', rawurlencode($data), 0);
	echo 'REFRESH THE PAGE TO SEE rawurlencode+setrawcookie to $_COOKIE[\'c\']';
}else{
	echo 'AFTER rawurlencode+setrawcookie:'. $_COOKIE['c'];
}
//http://cn.php.net/manual/en/function.setrawcookie.php#62848